object c3 {
	def main(): Unit = {
		if(new case3().start()) println("--------End of world Creation--------");
	}
}

class case3
{
	var blop: LivingCreature;
	var bob: Human;
	var fliper: Dolphin;
	var t: Int;
	def start(): Bool = 
	{
		/*Example with intensive use of extended classes with overriden or not functions
		  This Example also use if/while loops with a lot of function result based conditions
		*/
		t = 2;
		println("-----LivingCreature Object Creation-----");
		blop = new LivingCreature();

		println("-----Use of Function initialize-----");
		println("Initializing the creature : "+blop.initialize("blop"));

		println("-----Use of Function talk-----");
		println(blop.talk());

		println("-----Human Object Creation-----");
		bob = new Human();

		println("-----Use of function initialize received from superClass-----");
		println("Initializing the human : "+bob.initialize("bob"));

		println("-----Use of Overriden Function talk-----");
		println(bob.talk());

		println("-----Use of While loop looping on function setname result waiting for a specific variable value-----");
		while(!bob.setName("Joe",t))
		{
			println("-----Use of Overriden function talk-----");
			println(bob.talk());
			t = t+1;
		}
		println("-----End of While, name should finally be changed-----");

		println("-----Use of Overriden function talk-----");
		println(bob.talk());

		println("-----Use of function move as condition for If statement, received from superClass-----");
		if(bob.move() == true)
		{
			println("Your Human is moving!!");
		}
		else
		{
			println("What?? lazy human who doesn't want to move!! ");
		}

		println("-----Dolphin Object Creation-----");
		fliper = new Dolphin();

		println("-----Use of function initialize received from superClass-----");
		println("Initializing the dolphin : "+fliper.initialize("Fliper"));

		println("-----Use of Overriden function talk-----");
		println(fliper.talk());

		println("-----Use of overriden function move -----");
		if(fliper.move())
		{
			println("My dolphin moved!!");
		}

		return true;
        }
}

class LivingCreature 
{
	var name:String;
        
	def move(): Bool =
	{
		println("Moving [FAILED]");
		return false;
	}

	def talk(): String =
	{
		return "blup";
	}
	
	def initialize(s:String): String =
	{
		name=s;
		return "[OK]";
	}	
}

class Human extends LivingCreature
{
	var toRet: Bool;
	def setName(s:String, t:Int): Bool =
	{
		if(!(t == 5 || t < 5)) 
		{
			name=s;
			toRet = true;
		}
		else
		{
			toRet = false;
		}
		return toRet;
	}
	def talk(): String =
	{
		return ("my name is "+name);
	}		
}

class Dolphin extends LivingCreature
{
	def talk(): String =
	{
		return "squeeeeeeeeek";
	}

	def move(): Bool =
	{
		return true;
	}
}
